home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_02 / ED-157 / str_to_buf.c < prev    next >
C/C++ Source or Header  |  1993-09-10  |  2KB  |  55 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record (rhr@clio.rice.edu)
  3.  * 
  4.  * This file is part of ED.
  5.  * 
  6.  * ED is free software; you can redistribute it and/or modify it under the terms
  7.  * of the GNU General Public License as published by the Free Software Foundation.
  8.  * 
  9.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License along with ED
  14.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  15.  * Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17. #include "opsys.h"
  18.  
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <stdlib.h>
  22.  
  23. #include "rec.h"
  24. #include "buffer.h"
  25. #include "buf_dec.h"    /* kill buffers */
  26.  
  27. /******************************************************************************\
  28. |Routine: string_to_buf
  29. |Callby: do_grep journal parse_fnm
  30. |Purpose: Copies a string to a buffer.
  31. |Arguments:
  32. |    string is the string.
  33. |    buf is the buffer.
  34. \******************************************************************************/
  35. void string_to_buf(string,buf)
  36. register Char *string;
  37. register buf_ptr buf;
  38. {
  39.     register rec_ptr r;
  40.     register Int l;
  41.  
  42.     buffer_empty(buf);
  43.     if((l = strlen(string)))
  44.     {
  45.         r = (rec_ptr)imalloc(sizeof(rec_node));
  46.         r->data = (Char *)imalloc(l + 1);
  47.         strcpy(r->data,string);
  48.         r->length = l;
  49.         r->recflags = 1;    /* it is a freeable buffer */
  50.         insq(r,buf->first);    /* this works because buf->first = &buf->first after call to buffer_empty */
  51.         buf->nrecs = buf->direction = 1;
  52.     }
  53. }
  54.  
  55.